package com.laf.manage.controller.admin;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.laf.common.annotation.Log;
import com.laf.common.core.controller.BaseController;
import com.laf.common.core.domain.AjaxResult;
import com.laf.common.enums.BusinessType;
import com.laf.manage.domain.po.Category;
import com.laf.manage.service.ICategoryService;
import com.laf.common.utils.poi.ExcelUtil;

/**
 * 分类管理Controller
 *
 * @author zian
 * @date 2024-10-30
 */
@Api(tags = "分类管理管理")
@RestController("adminCategoryController")
@RequestMapping("/admin/category")
public class CategoryController extends BaseController {
    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询分类管理列表
     */
    @ApiOperation("查询分类管理列表")
    @PreAuthorize("@ss.hasPermi('manage:category:list')")
    @GetMapping("/list")
    public AjaxResult list(Category category) {
        List<Category> list = categoryService.selectCategoryList(category);
        return success(list);
    }



    /**
     * 导出分类管理列表
     */
    @ApiOperation("导出分类管理列表")
    @PreAuthorize("@ss.hasPermi('manage:category:export')")
    @Log(title = "分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Category category) {
        List<Category> list = categoryService.selectCategoryList(category);
        ExcelUtil<Category> util = new ExcelUtil<Category>(Category.class);
        util.exportExcel(response, list, "分类管理数据");
    }

    /**
     * 获取分类管理详细信息
     */
    @ApiOperation("获取分类管理详细信息")
    @PreAuthorize("@ss.hasPermi('manage:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(categoryService.getById(id));
    }

    /**
     * 新增分类管理
     */
    @ApiOperation("新增分类管理")
    @PreAuthorize("@ss.hasPermi('manage:category:add')")
    @Log(title = "分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Category category) {
        boolean b = categoryService.addCategory(category);
        return toAjax(b);
    }

    /**
     * 修改分类管理
     */
    @ApiOperation("修改分类管理")
    @PreAuthorize("@ss.hasPermi('manage:category:edit')")
    @Log(title = "分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Category category) {
        boolean b = categoryService.editCategory(category);
        return toAjax(b);
    }

    /**
     * 删除分类管理
     */
    @ApiOperation("删除分类管理")
    @PreAuthorize("@ss.hasPermi('manage:category:remove')")
    @Log(title = "分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult DelByIds(@PathVariable Long id) {
        boolean b = categoryService.delById(id);
        return toAjax(b);
    }
}
